#ifndef __FSM_H__
#define __FSM_H__

#include "cocos2d.h"

USING_NS_CC;
using namespace std;

class FSM :public Ref
{
public:

    bool init();
    static FSM* create(string state, function<void()> onEnter = nullptr);
    FSM(string state, function<void()> onEnter = nullptr);
    FSM* addState(string state, function<void()> onEnter = nullptr);
    FSM* addEvent(string eventName, string from, string to);
    bool containState(string stateName);
    void printState();
    void doEvent(string eventName);
    bool canDoEvent(string eventName);
    void setOnEnter(string state, function<void()> onEnter);
    string getState() { return _currState; }
private:
    void changeToState(string state);
private:
    set<string> _states;
    unordered_map<string, unordered_map<string, string>> _events;//(string state,string from,string to)
    unordered_map<string, function<void()>> _onEnters;
    string _currState;
    string _prevState;
};

#endif